package com.xyd.auth.security.custom;

import org.springframework.security.crypto.password.PasswordEncoder;
import com.xyd.common.util.MD5;
import org.springframework.stereotype.Component;

@Component
public class CustomMD5PasswordEncoder implements PasswordEncoder {
    /**
     * 密码加密
     * @param rawPassword
     * @return
     */
    @Override
    public String encode(CharSequence rawPassword) {
        return MD5.encrypt(rawPassword.toString());
    }

    /**
     * 密码校验
     * @param rawPassword 用户提交的密码
     * @param encodedPassword 正确密码(数据库中查询对象的密码)编码后得到的字符串
     * @return 返回一个boolean布尔值表示是否校验通过
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(MD5.encrypt(rawPassword.toString()));
    }
}
